import types


def compile_module(code:str, module_name:str) -> types.ModuleType:
    """Compile a string of Python code into a module.

    Args:
        code (str): The Python code to compile.
        module_name (str): The name of the module.

    Returns:
        types.ModuleType: The compiled module.
    """
    module = types.ModuleType(module_name)
    exec(code, module.__dict__, module.__dict__)
    return module
